home *** CD-ROM | disk | FTP | other *** search
- /*
- * The original copyright owners of the accompanying source code files have
- * agreed to place such code into the public domain. Accordingly, anyone
- * who receives or obtains a copy of such source code is freely entitled to
- * reproduce, use and otherwise exploit such code (including the right to
- * make derivative works), at his/her own risk and expense, without any
- * obligation or liability to the original copyright owners.
- *
- * We would appreciate (but do not require) that the following message be
- * included in any derivative works:
- *
- * "Portions of this program were developed by Peter Broadwell, Rob Myers
- * and Robin Schaufler while working in Silicon Valley."
- *
- * The accompanying source code files and related documentation materials
- * are distributed on an "AS IS" basis, without any warranties or
- * guarantees of any kind. All implied warranties, including the implied
- * warranties of merchantability and of fitness for any particular purpose,
- * are expressly disclaimed.
- */
- #include "gl.h"
- #include "get.h"
- #include "device.h"
- #include "geom.h"
- #include "class.h"
- #include "classIds.h"
- #include "selectors.h"
- #include "mbox.h"
- #include "individual.h"
- #include "behavior.h"
- #include "doers.h"
- #include "panel.h"
- #include "pick.h"
- #include "camera.h"
- #include "colors.h"
- #include "bub.h"
-
- extern individual *us;
- extern masterPanel *thePanel;
- extern int controls, allbuttons;
- extern point2d curWindow;
-
- char frozen = FALSE;
- char bullet = FALSE;
- char timeit = FALSE;
- char warping = FALSE;
- char quit = FALSE;
- char hz30;
- char dobackground = 3; /* >0 if need to redraw background */
-
- void setCameraView(individual*);
- void refreshBowl(camera*);
-
-
- take(s)
- register individual *s;
- {
- static point last;
- static int lastzoom = 0;
- static int moving = 0;
- static int wasmoving = 0;
-
- setCameraView(s);
-
- if ((s->position.x != last.x) || (s->rotation.y != last.y) ||
- (s->rotation.z != last.z) || (((camera *)s)->zoom != lastzoom)) {
- fishWritemask(BACKGROUND);
- fishColor(WATER_COLOR);
- clear();
- moving = TRUE;
- }
- else moving = FALSE;
-
- if (lastzoom == 0) {
- fishWritemask(BACKGROUND);
- fishColor(WATER_COLOR);
- clear();
- dobackground = 3; /* clear bad initial frame on startup */
- }
-
- if ((moving == FALSE) && (wasmoving == TRUE)) {
- dobackground = 2; /* redraw background */
- }
-
- last.x = s->position.x;
- last.y = s->rotation.y;
- last.z = s->rotation.z;
- lastzoom = ((camera *)s)->zoom;
- wasmoving = moving;
- }
-
- /* ARGSUSED */
- leftright(s,argtype,incr)
- register individual *s;
- long argtype;
- long incr;
- {
- /* printf("leftright: %d <= %d\n",s->rotation.z, incr); /**/
- s->rotation.z = incr;
- }
-
- /* ARGSUSED */
- updown(s,argtype,incr)
- register individual *s;
- long argtype;
- long incr;
- {
- /* printf("updown: %d <= %d\n",s->rotation.y, incr); /**/
- s->rotation.y = incr;
- }
-
- /* ARGSUSED */
- inout(s,argtype,incr)
- register individual *s;
- long argtype;
- long incr;
- {
- /* printf("inout: %d <= %d\n",s->position.x, incr); /**/
- s->position.x = incr;
- }
-
- /* ARGSUSED */
- zoom(s,argtype,incr)
- register camera *s;
- long argtype;
- long incr;
- {
- /* printf("zoom: %d <= %d\n",s->zoom, incr); /**/
- s->zoom = incr;
- if(s->zoom < 2)
- s->zoom = 2;
- if(s->zoom > 1800)
- s->zoom = 1800;
- }
-
- /*
- * restore default viewing parameters for camers
- */
- home(s)
- register individual *s;
- {
- s->position.x = 10000;
- s->position.y = 10000;
- s->position.z = 10000;
- s->rotation.x = 0;
- #ifdef LONELY
- s->rotation.y = 0;
- #else /* LONELY */
- s->rotation.y = 900;
- #endif /* LONELY */
- s->rotation.z = 0;
- ((camera *)s)->zoom = 900;
- }
-
- getMouse(s)
- register camera *s;
- {
- register long dev = 0;
- static short val;
- long mx, my;
- char picking = FALSE;
- long nhit;
- short hitlist[HITENTRIES];
- hitstruct hit;
- Object pickObj;
- long penup = FALSE;
-
- static long downdev = 0;
- static long lastval = 0;
- #ifdef DEBUG
- static long lastx, lasty;
- #endif
- static Object lastObj = NULL;
-
- if (qtest()) {
- if ((dev = qread(&val)) == MIDDLEMOUSE ||
- dev == LEFTMOUSE ||
- dev == RIGHTMOUSE ||
- dev == BKEY ||
- dev == FKEY ||
- dev == QKEY ||
- dev == SKEY ||
- dev == ZKEY ||
- dev == VIRGULEKEY ||
- dev == ESCKEY ) {
- if (val == 0) {
- switch (dev) {
- case RIGHTMOUSE:
- case MIDDLEMOUSE:
- case LEFTMOUSE:
- if (lastval == 1)
- penup = TRUE; /* to downdev for pen-up process */
- else downdev = 0;
- break;
- case ZKEY:
- warping = FALSE;
- break;
- default:
- break;
- }
- }
- else if (val == 1) {
- switch (dev) {
- case RIGHTMOUSE:
- case MIDDLEMOUSE:
- case LEFTMOUSE:
- downdev = dev;
- break;
- case QKEY:
- home(s); /* restore default viewing parameters */
- break;
- case FKEY:
- frozen = frozen ? 0 : 1;
- break;
- case BKEY:
- bullet = bullet ? 0 : 1;
- break;
- case ESCKEY:
- quit = quit ? 0 : 1;
- break;
- case VIRGULEKEY:
- timeit = timeit ? 0 : 1;
- break;
- case SKEY:
- if(hz30)
- setmonitor(HZ30);
- else
- setmonitor(HZ60);
- hz30 = !hz30;
- break;
- case ZKEY:
- warping = TRUE;
- break;
- default:
- break;
- }
- }
- }
- }
- if (downdev) {
- mx = getvaluator(MOUSEX);
- my = getvaluator(MOUSEY);
- switch (downdev) {
- /*********************************** the way it was ***********
- case LEFTMOUSE:
- Msg(s,LEFTRIGHT, INTARG,
- (long)((mx - (float)(XMAXSCREEN/2))/ XMAXSCREEN * 3600));
- Msg(s,UPDOWN, INTARG,
- (long)((float)(YMAXSCREEN - my)/ YMAXSCREEN * 1800));
- break;
- case MIDDLEMOUSE:
- if (warping)
- Msg(s,INOUT, INTARG,
- (long)((float)(YMAXSCREEN - my)/ YMAXSCREEN * 20000));
- else Msg(s,ZOOM, INTARG,
- (long)((float)(YMAXSCREEN - my)/ YMAXSCREEN * 1800));
- break;
- case RIGHTMOUSE:
- conduct the hit processing shown under MIDDLEMOUSE below
- break;
- ************************************ the way it was *************/
-
- case LEFTMOUSE:
- case RIGHTMOUSE:
- /*************
- if (! allbuttons)
- break;
- /**********/
- case MIDDLEMOUSE:
- /* conduct hit processing */
- pushmatrix();
- /* BUG: see refreshBowl */
- viewport(0,curWindow.y, 0,curWindow.y);
- pick(hitlist, NNAMES);
- refreshBowl(s); /* refresh bowl's viewport contents */
- nhit = gethit(&hit, hitlist, endpick(hitlist));
- /* hit object is first item in hitlist */
- pickObj = (nhit >0) ? hit.hitlist[0] : NULL;
- if(pickObj == NULL) {
- /* BUG: see refreshControls */
- pushviewport();
- viewport(curWindow.y, curWindow.x, 0, curWindow.y);
- pick(hitlist, NNAMES);
- refreshControls(); /* panel's viewport contents */
- nhit = gethit(&hit, hitlist, endpick(hitlist));
- /* hit object is first item in hitlist */
- pickObj = (nhit >0) ? hit.hitlist[0] : NULL;
- popviewport();
- }
- hit.x = mx;
- hit.y = my;
- popmatrix();
-
- /* look for button state and hit Object changes */
- if (lastval == 0 && val == 1)
- picking = BEGINSELECT;
- else if (lastval == 1 && val == 0)
- picking = ENDSELECT;
- else if (lastObj == pickObj)
- picking = CONTSELECT;
- else {
- if (lastObj)
- Msg(lastObj, OLDSELECT, HITARG, &hit);
- picking = NEWSELECT;
- }
-
- if (nhit && pickObj) {
- /* direct input to the picked object */
- /* printf("pick: sent %d to 0x%x\n", picking, pickObj);/* */
- Msg(pickObj, picking, HITARG, &hit);
- }
- else {
- /* direct input which misses all other objects to US */
- /* printf("pick: sent %d to US\n", picking); /* */
- Msg(us, picking, HITARG, &hit);
- }
- break;
- }
- #ifdef DEBUG
- lastx = mx;
- lasty = my;
- #endif
- lastval = val;
- lastObj = pickObj;
- }
- else if (val == 0) lastval = val;
-
- if (penup) {
- penup = FALSE;
- downdev = 0; /* end of pen-up event */
- }
-
- }
-
- /*
- * setup viewing transformation from camera's information
- */
- void
- setCameraView(s)
- register individual *s;
- {
- perspective(((camera *)s)->zoom,1.0,100.0,110000.0);
- polarview((float)s->position.x,s->rotation.z,s->rotation.y,0);
- }
- /*
- * refresh bowl's viewport contents for picking purposes
- */
- void
- refreshBowl(camera* c)
- {
- setCameraView((individual*)c);
- /* BUG: cant change viewport durring picking */
- /* viewport(0,curWindow.y, 0,curWindow.y); /* */
- pushmatrix();
- callobj((Object)us);
- popmatrix();
- }
-
- /*
- * refresh control panel's viewport contents for picking purposes
- */
- refreshControls()
- {
- if (controls) {
- /* pushviewport(); /* */
- /* BUG: cant change viewport durring picking */
- /* viewport(curWindow.y, curWindow.x, 0, curWindow.y); /* */
- /******
- gl_makepickmat();
- /******/
- ortho2(0.0, 256.0, 767.0, 0.0);
- pushmatrix();
- backface(FALSE);
- callobj((Object)thePanel);
- popmatrix();
- /* popviewport(); /* */
- }
- }
-